<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
 <% 
String path = request.getContextPath(); 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<script type="text/javascript" src="<%=basePath %>static/js/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
	$(function(){
		$("#cardNo").blur(function() {
			var cardNo = $("#cardNo").val();
			var args={cardNo:cardNo}
			$.ajax({
				url:"<%=basePath %>users/checkCardNo",
				type:"post",
				data:args,
				success:function(data){
					/* //获取类对象
					alert(data.name+":"+data.age); */
					//可以获取单个参数
					/* if(data==true) {
						$("#cardError").text("乘车人已存在");
					} */
					//可以接收list
					$.each(data,function(index,result){
						alert(result.name+":"+result.age);
					});
				},
				error:function(){
					alert("程序出错，请联系管理员");
				}
			});
		});
		
//ajax表单提交，返回表单数据数据
<%-- $("#button").click(function(){
			$.ajax({
				url:"<%=basePath%>users/saveConcat",
				cache:false,
				data:$("#form1").serialize(),
				type:"post",
				success:function(result){
					alert(result.name);
				}
			});
		});  --%>
	//ajax表单提交json格式
<%-- $("#button").click(function(){
	var name=$("#name").val();
	var age = $("#age").val();
	var args={name:name,age:age}
	$.ajax({
		url:"<%=basePath%>users/saveConcat",
		cache:false,
		contentType : 'application/json; charset=utf-8',
		data:JSON.stringify(args),
		type:"post",
		success:function(result){
			alert(result.name);
		}
	}); 
	});--%>
	//多个简单参数ajax传递
<%-- 	$("#button").click(function(){
		var name=$("#name").val();
		var age = $("#age").val();
		var args={name:name,age:age}
		$.ajax({
			url:"<%=basePath%>users/saveConcat",
			cache:false,
			data:args,
			type:"post",
			success:function(result){
				alert(result.name);
			}
		});
	});  --%>
	
	$("#button").click(function(){
		var args=[];
		var name=$("#name").val();
		var age = $("#age").val();
		var arg={name:name,age:age};
		args.push(arg);
		args.push(arg);
		$.ajax({
			url:"<%=basePath%>users/saveConcat",
			cache:false,
			contentType : 'application/json; charset=utf-8',
			data:JSON.stringify(args),
			type:"post",
			success:function(result){
				alert(result.name);
			}
		}); 
	});
});
</script>
<body>
<form action="" method="post" id="form1">
身份证：<input type="text" name="cardNo" id="cardNo" /> <label id="cardError" > </label><br >
姓名： <input type="text" name="name" id="name" /><br >
性别	<input type="text" name="sex" id="sex" /><br >
年龄：	<input type="text" name="age" id="age" /><br >
	电话：<input type="text" name="tel" id="tel" /><br >
	<input type="button" id="button" value="添加">
	</form>
</body>
</html>
